package service;

import dao.OrdersDao;
import domain.Car;
import domain.Orders;
import domain.Page;

import java.util.ArrayList;
import java.util.List;

public class OrderService {
    OrdersDao od = new OrdersDao();

    public List<Orders> findOrderByUserId(int userId) {
        return od.findOrderByUserId(userId);
    }

    public Orders findOrderById(int id){
        return od.findOrderById(id);
    }

    public List<Page> getPages(int user_id){
        int total = od.getTotal(user_id);
        int pageSize = od.pageSize;
        int pageCount = (total%pageSize==0?total/pageSize:total/pageSize+1);
        List<Page> pages=new ArrayList<Page>();
        for(int i=1;i<=pageCount;i++) {
            Page page=new Page();
            page.setPageNo(i);
            page.setPageText("No."+i);
            pages.add(page);
        }
        return pages;
    }
}
